<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
     <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<script>

var treeHref = "javascript:findByMenuId({mid});";
getTrees();
function getTrees(){
	var sysType = '${vo.sysType}';
	$.ajax({
		type : 'post',
		cache : false,
		dataType : 'json',
		url : "${pageContext.request.contextPath}/help/topic/menus.action",
		loading : '正在获取...',
		data : {"vo.sysType":sysType},
		success : function(menus) {
			var tree = "";
			for(var i=0;i<menus.length;i++){
				tree += '<LI><A class="dropdown-toggle" onclick="javascript:findByMenuId('+menus[i].id+');" href="'+treeHref.replace("{mid}",menus[i].id)+'"><I  class="icon-bar-chart"></I><SPAN class="menu-text" id="menuId_'+menus[i].id+'"> '+menus[i].text+'</SPAN><B class="arrow icon-angle-down"></B></A><UL class="submenu">';
				for(var j=0;j<menus[i].children.length;j++){
					tree += getElement(menus[i].children[j]);
				}
				tree += '</UL></LI>';
			}
			
			$("#tree_f").append(tree);
			findByMenuId(${vo.mid});
			//$("#tree_f").append('<LI><A href="#"><I class="icon-list-alt"></I><SPAN class="menu-text" id="treeOther"> 其他功能 </SPAN></A></LI>');
		},
		error : function(message) {
			alert("获取功能树出错");
		}
	});
}

function getElement(child){
	
	if(child.children==undefined||child.children==''||child.children.length==0){
		return '<LI><A href="'+treeHref.replace("{mid}",child.id)+'"><I class="icon-double-angle-right"></I><SPAN pid="'+child.pid+'" id="menuId_'+child.id+'" class="menu-text">'+child.text+'</SPAN></A></LI>';
	}
	 var count = child.children.length;
		var element = '<LI><A class="dropdown-toggle" href="'+treeHref.replace("{mid}",child.id)+'"><I class="icon-double-angle-right"></I><SPAN pid="'+child.pid+'" id="menuId_'+child.id+'" class="menu-text">'+child.text+'</SPAN><B class="arrow icon-angle-down"></B></A>';
		element += '<UL class="submenu">';
		for(var i = 0; i < count; i++){
			element += getElement(child.children[i]);
		}
		element += "</UL></LI>";
		return element;
}



function findByMenuId(mid){
	if(mid==null||mid==undefined){
		mid=="";
	}
	if($("#chatPageContent").is(":visible")==true){//正在回复
		return ;
	}
	$("#mid").val(mid);
	<c:if test="${vo.authority eq '1' }">
	toShowMenuDesc();
	</c:if>
	this.findRows('',1);
	var banner="";
	if(mid!=undefined){
	var text = $("#menuId_"+mid).html();
	$("#launchMenuName").html("("+text+")");//launch_topic
	this.findMneuDesc();
	 banner = getBanner(mid,1);
	}else{
		$("#menuDesc").html("");
		$("#launchMenuName").html("");
		banner = '<LI class="active">首页</LI>';
	}
	$("#banner").html(banner);
	
}


function getBanner(mid,i){
	var html = '';
	var regex = '<SPAN class="divider"><I class="icon-angle-right arrow-icon"></I></SPAN>';
	var pid = $("#menuId_"+mid).attr("pid");
	var text = $("#menuId_"+mid).html();
	if(pid==0||pid==undefined){
		if(i==1){
		return '<LI class="active">'+text+'</LI>';
		}else{
			return '<LI><A href="javascript:findByMenuId('+mid+');">'+text+'</A></LI>'+regex;
		}
	}else{
		html = getBanner(pid,++i) + '<LI class="active">'+text+'</LI>' ;
	}
	return html;
}
</script>

<UL class="nav nav-list" id ='tree_f'>
  <LI class="active"><A href="javascript:findByMenuId();"><I class="icon-dashboard"></I><SPAN class="menu-text"> 功能导航 </SPAN></A></LI>
  </UL>